package com.zhouzi.zhaoyang.util;

import androidx.recyclerview.widget.RecyclerView;

import com.zhy.http.okhttp.callback.Callback;

import cn.jpush.android.helper.Logger;
import okhttp3.Call;
import okhttp3.MediaType;
import okhttp3.Response;

/**
 * @author zxt
 * Created on 2019/7/18 0018
 * explain:
 */
public abstract class SCallBack extends Callback<String> {
    private String TAG = "SCallBack";
    private RecyclerView recyclerView;
    private boolean isConnect;

    public SCallBack(RecyclerView recyclerView) {
        this.recyclerView = recyclerView;
    }

    public SCallBack() {

    }

    @Override
    public String parseNetworkResponse(Response response, int id) throws Exception {
        MediaType mediaType = response.body().contentType();
        String surl = response.request().url().toString();
        String subtype = mediaType.subtype();

        Logger.e(TAG, "url=" + response.request().url().toString());

        Logger.e(TAG, "mediaType=" + mediaType.toString());
        Logger.e(TAG, "subtype=" + subtype);
        String resp = response.body().string();
        Logger.e(TAG, "resp=" + resp);
//        LogUtil.e(TAG, "headers=" +response.headers().toString());
        return resp;
    }

    @Override
    public void onError(Call call, Exception e, int id) {
        Logger.e(TAG, "onError url=" + call.request().url().toString());
        Logger.e(TAG, "onError===" + e.getMessage());
        Logger.e(TAG, "onError===" + e.getCause());

        onError(call, e);
    }

    public abstract void onError(Call call, Exception e);

    @Override
    public void onResponse(String response, int id) {
        // 有网络
        Logger.e("status===", recyclerView+":::::"+isConnect);
        if (isConnect && recyclerView!= null){
            recyclerView.setBackgroundResource(0);
        }
    }




}
